package com.castle.fortress.admin.jmreport.service.impl;

import cn.hutool.core.util.StrUtil;

import com.castle.fortress.common.utils.ConvertUtil;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.castle.fortress.admin.jmreport.entity.CastleJmrAuditEntity;
import com.castle.fortress.admin.jmreport.dto.CastleJmrAuditDto;
import com.castle.fortress.admin.jmreport.mapper.CastleJmrAuditMapper;
import com.castle.fortress.admin.jmreport.service.CastleJmrAuditService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;

/**
 * 积木报表可见权限表 服务实现类
 *
 * @author castle
 * @since 2023-10-12
 */
@Service
public class CastleJmrAuditServiceImpl extends ServiceImpl<CastleJmrAuditMapper, CastleJmrAuditEntity> implements CastleJmrAuditService {
    /**
    * 获取查询条件
    * @param castleJmrAuditDto
    * @return
    */
    public QueryWrapper<CastleJmrAuditEntity> getWrapper(CastleJmrAuditDto castleJmrAuditDto){
        QueryWrapper<CastleJmrAuditEntity> wrapper= new QueryWrapper();
        if(castleJmrAuditDto != null){
            CastleJmrAuditEntity castleJmrAuditEntity = ConvertUtil.transformObj(castleJmrAuditDto,CastleJmrAuditEntity.class);
            wrapper.like(castleJmrAuditEntity.getId() != null,"id",castleJmrAuditEntity.getId());
            wrapper.like(castleJmrAuditEntity.getJmrId() != null,"jmr_id",castleJmrAuditEntity.getJmrId());
            wrapper.like(StrUtil.isNotEmpty(castleJmrAuditEntity.getDepts()),"depts",castleJmrAuditEntity.getDepts());
            wrapper.like(StrUtil.isNotEmpty(castleJmrAuditEntity.getUsers()),"users",castleJmrAuditEntity.getUsers());
        }
        return wrapper;
    }


    @Override
    public IPage<CastleJmrAuditDto> pageCastleJmrAudit(Page<CastleJmrAuditDto> page, CastleJmrAuditDto castleJmrAuditDto) {
        QueryWrapper<CastleJmrAuditEntity> wrapper = getWrapper(castleJmrAuditDto);
        Page<CastleJmrAuditEntity> pageEntity = new Page(page.getCurrent(), page.getSize());
        Page<CastleJmrAuditEntity> castleJmrAuditPage=baseMapper.selectPage(pageEntity,wrapper);
        Page<CastleJmrAuditDto> pageDto = new Page(castleJmrAuditPage.getCurrent(), castleJmrAuditPage.getSize(),castleJmrAuditPage.getTotal());
        pageDto.setRecords(ConvertUtil.transformObjList(castleJmrAuditPage.getRecords(),CastleJmrAuditDto.class));
        return pageDto;
    }


    @Override
    public List<CastleJmrAuditDto> listCastleJmrAudit(CastleJmrAuditDto castleJmrAuditDto){
        QueryWrapper<CastleJmrAuditEntity> wrapper = getWrapper(castleJmrAuditDto);
        List<CastleJmrAuditEntity> list = baseMapper.selectList(wrapper);
        return ConvertUtil.transformObjList(list,CastleJmrAuditDto.class);
    }
}

